package guoanmaker.operator.business.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import guoanmaker.operator.business.model.OperatorComplaintType;
import guoanmaker.operator.business.service.OperatorComplaintTypeServiceInterface;
import guoanmaker.operator.helper.common.AjaxJson;
import guoanmaker.operator.helper.common.abstractobj.ApiController;
import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping(ApiController.OPERATOR_CITY)
public class OperatorComplaintTypeController {

	@Autowired
	private  AjaxJson ajaxJson;
	
	@Autowired
	private OperatorComplaintTypeServiceInterface operatorComplaintTypeServiceInterface;
	
	@ApiOperation(value = "新增/修改投诉类型", notes = "新增/修改投诉类型")
    @PostMapping(value = "saveOperatorComplaintType")
    public AjaxJson saveOperatorComplaintType(@RequestBody OperatorComplaintType operatorComplaintType) {
		try {
			int a=operatorComplaintTypeServiceInterface.saveOperatorComplaintType(operatorComplaintType);
			if(a==-2){
				ajaxJson.setSuccess(true).setStatus(230).setData("类别名称已存在");
			}
			else{
				ajaxJson.setSuccess(true).setStatus(200).setData("保存成功");
			}
		} catch (Exception e) {
			e.printStackTrace();
			ajaxJson.setSuccess(true).setStatus(250).setData("保存错误");
		}
        return ajaxJson;
    }
	@ApiOperation(value = "分页查询投诉类型", notes = "分页查询投诉类型")
	@PostMapping(value = "selectOperatorComplaintType")
	public AjaxJson selectOperatorComplaintType(Integer page,Integer size) {
		try {
			Map<String,Object> map=operatorComplaintTypeServiceInterface.selectOperatorComplaintType(page, size);
			int a=(int) map.get("count");
			if(a>0){	
				ajaxJson.setSuccess(true).setStatus(200).setData(map);
			}
			else{
				ajaxJson.setSuccess(true).setStatus(230).setData("无数据");
			}
			
		} catch (Exception e) {
			e.printStackTrace();
			ajaxJson.setSuccess(true).setStatus(250).setData("查询失败");
		}


		return ajaxJson;
	}
	@ApiOperation(value = "批量删除投诉类型", notes = "批量删除投诉类型")
	@PostMapping(value = "deleteOperatorComplaintType")
	public AjaxJson deleteOperatorComplaintType(String id) {
		try {
			operatorComplaintTypeServiceInterface.deleteOperatorComplaintType(id);
			ajaxJson.setSuccess(true).setStatus(200).setData("删除成功");
		} catch (Exception e) {
			e.printStackTrace();
			ajaxJson.setSuccess(true).setStatus(250).setData("删除失败");
		}
		return ajaxJson;
	}
}
